library dez1;

uses
  System.SysUtils,
  System.Classes,
  ActiveX,
  AxCtrls,
  pFIBDatabase,
  Vcl.Forms,
  dxCore,
  PluginAPI in '..\..\Headers\PluginAPI.pas';

{$R *.res}
{$E .plg}

type
  TPlugin = class(TInterfacedObject, IUnknown, IPlugin, IImportDB)
  private
    FCore: ICore;
    fMainDB : TpFIBDatabase;
  protected
    // IPlugin
    function GetMask: WideString; safecall;
    function GetDescription: WideString; safecall;
    //IImportDB
    procedure SetDB(const fdb :TpFIBDatabase); safecall;
    procedure SetApp(const App :Integer); safecall;
  public
    constructor Create(const ACore: ICore);
    property MainDB :TpFIBDatabase read fMainDB write SetDB;
  end;
var
  DllApp : TApplication;

{ TPlugin }

constructor TPlugin.Create(const ACore: ICore);
begin
  inherited Create;
  FCore := ACore;
  Assert(FCore.Version >= 1);
end;

function TPlugin.GetDescription: WideString;
begin
  //
end;

function TPlugin.GetMask: WideString;
begin
  //
end;

procedure TPlugin.SetApp(const App: Integer);
begin
  DllApp := Application;
  Application:=TApplication(App);
end;

procedure TPlugin.SetDB(const fdb: TpFIBDatabase);
begin
  MainDB:=fdb;
end;

function Init(const ACore: ICore): IPlugin; safecall;
begin
  Result := TPlugin.Create(ACore);
  dxInitialize;
end;

procedure Done; safecall;
begin
  dxFinalize;
  Application := DllApp;
end;

exports
  Init name SPluginInitFuncName,
  Done name SPluginDoneFuncName;

//begin
  //ReportMemoryLeaksOnShutdown := True;

end.
